package com.create.rdjc.util;

import com.create.rdjc.model.FieldModel;
import com.create.rdjc.model.TableFiledModel;
import com.create.rdjc.model.TableModel;

import java.util.ArrayList;
import java.util.List;

public class TableUtils {


    public static List<TableModel> getTableList(List<TableFiledModel> list){
        List<TableModel> tables=new ArrayList<>();
        TableModel tableModel=null;

        for (TableFiledModel m : list) {
            if (m.getOrder() == 1) {
                tableModel = new TableModel();
                tableModel.setTableEn(m.getTableEn());
                tableModel.setMode(m.getMode());
                tableModel.setTableCn(m.getTableCn());
                tables.add(tableModel);
            }
            FieldModel fieldModel = new FieldModel();
            fieldModel.setFieldCn(m.getFieldCn());
            fieldModel.setFieldEn(m.getFieldEn());
            fieldModel.setDataType(m.getDataType());
            fieldModel.setOrder(m.getOrder());
            fieldModel.setIsNull(m.getIsNull());
            fieldModel.setIsParamKey(m.getIsParamKey());
            fieldModel.setAutoId(m.getAutoId());
            fieldModel.setFieldDefault(m.getFieldDefault());
            fieldModel.setDataTypeKey(m.getDataTypeKey());
            fieldModel.setLength(m.getLength());
            tableModel.getFields().add(fieldModel);

        }

        return tables;
    }
}
